<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
<!--
 * Created on Aug 20, 2011
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
-->
<?

require_once("bizlayer/player_mgmt.php");

$emailNotFound = false;
$pwSent = false;
$emailAddr = "";

if(isset($_POST) and $_SERVER["REQUEST_METHOD"] == "POST"){
	$emailAddr = (isset($_POST["email_address"]))?trim($_POST["email_address"]):"";
	$result = PlayerMgmt::searchPlayer(null,null,null,$emailAddr,null,null,null,null,null);
	$emailNotFound = false;
	if(count($result) == 1){
		$player = $result[0];
		PlayerMgmt::updatePassword($player->playerid,md5("wjc87"),0);
		
		$to = $player->emailAddress;
		$subject = "Walter J Corbett: Your password has been reset.";
		$message = "Your temporary password is \"wjc87\""; 
		$headers = "From: me@japanesemasshole.com\r\n".
				"Reply-To: me@japanesemasshole.com\r\n".
				"X-Mailer: PHP/". phpversion();
				
		mail($to, $subject,$message,$headers);
		$pwSent = true;	
	}
	else{
		$emailNotFound = true;
		$pwSent = false;	
	}
}
?>
	<head>
		<title>Walter J Corbett Intivational</title>
		<link href="assets/styles/liquid.css" rel="stylesheet" type="text/css" />
	</head>
<body>
<div id="maincontainer">
	
	<?php
	$hideLogin = true;
	require_once("components/header.inc.php");
	
	
	
	?>
	<form name="resetform" method="post" action="reset_password.php">
	<div id="contentwrapper">
		<div id="contentcolumn">
			<div class="innertube" style="text-align:center;margin-top:20%;margin-bottom:40%">
				<?if(!$pwSent){?>
					<fieldset>
						<legend>Please enter your email.</legend>
						Email Address: <?printf("<input type=\"text\" name=\"email_address\" value=\"%s\"/>",$emailAddr)?>
						<input type="submit" name="reset_submit" value="Reset password"/>
						<?if($emailNotFound){?>
						<strong style="color:red">Email not found.</strong>
						<?}?>					
					</fieldset>
				<?}else{?>	
					<p>Your password has been sent.</p>
					<a href="index.php">Go back home</a>
				<?}?>
			</div>
		</div>
	</div>
	</form>
	<div id="leftcolumn">
		<div class="innertube">Right column</div>
	</div>
	<?php
	require_once("components/footer.inc.php");
	?>
	
</div> 
</body>
</html>
